package com.hww.web;

import com.hww.entity.User;
import com.hww.mq.producer.MQProducerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: youdao.hww
 * @Date: 4/16/24
 * @Desc:
 */
@RestController
@Slf4j
public class MqTestController {

    @Autowired
    private MQProducerService mqProducerService;


    @PostMapping("testNormalMqWithoutKey")
    public void testNormalMqWithoutKey() {
        User user = new User();
        user.setId(1L);
        user.setAge(10);
        user.setName("hww");
        mqProducerService.sendSimple("Topic-user", "user", user);
    }


    @PostMapping("testNormalMq")
    public void testNormalMq() {
        User user = new User();
        user.setId(1L);
        user.setAge(10);
        user.setName("hww");
        for (int i = 0; i < 100; i++) {
            String key = "user_" + i;
            mqProducerService.send("Topic-user", "user", user, key);
            log.info("----------------------------------消息发送,key:{}", key);
        }
    }


    @PostMapping("testUserMq")
    public void testMq() {
        User user = new User();
        user.setId(1L);
        user.setAge(10);
        user.setName("hww");

        for (int i = 0; i < 100; i++) {
            String key = "user_" + i;
            mqProducerService.sendFIFOMsg("Topic-user", "user", user, key);
            log.info("----------------------------------消息发送,key:{}", key);
        }
    }


    @PostMapping("testDelayMq")
    public void testDelayMq() {
        User user = new User();
        user.setId(1L);
        user.setAge(10);
        user.setName("hww");
        mqProducerService.sendDelayMsg("Topic-user", "user", 2);
        log.info("----------------------------------消息发送");

    }


}
